package com.cn.JUC.utils.case10;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @Title 执行到一半，等待T2的结果，执行继续执行
 * @Description T1Task需要执行的任务：洗水壶、烧开水、泡茶
 * @Author CAI ZHAI
 * @Date 2021/9/6 16:08
 **/
class T1Task implements Callable<String>{
    FutureTask<String> ft2;
    // T1任务需要T2任务的FutureTask
    T1Task(FutureTask<String> ft2){
        this.ft2 = ft2;
    }
    @Override
    public String call() throws Exception {
        System.out.println("T1:洗水壶...");
        TimeUnit.SECONDS.sleep(1);
        
        System.out.println("T1:烧开水...");
        TimeUnit.SECONDS.sleep(5);
        // 获取T2线程的茶叶
        String tf = ft2.get();
        System.out.println("T1:拿到茶叶:"+tf);
        
        System.out.println("T1:泡茶...");
        return "上茶:" + tf;
    }
}
